const fs = require("fs");

// fs.readFile("./resources/为学.md", (err1, data1) => {
//   fs.readFile("./resources/观书有感.md", (err2, data2) => {
//     fs.readFile("./resources/插秧诗.md", (err3, data3) => {
//       const data = data1 + "\n" + data2 + "\n" + data3;
//       console.log(data);
//     });
//   });
// });

// 使用promise实现
const p = new Promise((resolve, reject) => {
  fs.readFile("./resources/为学.md", (err, data) => {
    resolve(data);
  });
});

p.then(value => {
  return new Promise((resolve, reject) => {
    fs.readFile("./resources/插秧诗.md", (err, data) => {
      resolve([value, data]);
    });
  });
})
  .then(value => {
    return new Promise((resolve, reject) => {
      fs.readFile("./resources/观书有感.md", (err, data) => {
        value.push(data);
        resolve(value.join("\n"));
      });
    });
  })
  .then(value => {
    console.log(value);
  });
